package com.springboot.chongwu.controller.sys;

import cn.dev33.satoken.stp.StpUtil;
import com.springboot.chongwu.entity.SysMenu;
import com.springboot.chongwu.entity.req.SysMenuReq;
import com.springboot.chongwu.service.ISysMenuService;
import com.springboot.chongwu.util.ResultView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-06-17
 */
@Validated
@RestController
@RequestMapping("/api/admin/menu")
public class SysMenuController {

    @Autowired
    private ISysMenuService iHjMenuService;

    /**
     * 获取当前用户树结构
     * @return
     */
    @GetMapping("/getMenuTree")
    public ResultView getMenuTree(){
        return this.iHjMenuService.getMenuTree(StpUtil.getLoginIdAsString());
    }

    /**
     * 菜单列表
     * @return
     */
    //@SaCheckPermission("menu:list")
    @GetMapping("/list")
    public ResultView list(String menuName) {
        List<SysMenu> hjMenuList=this.iHjMenuService.getListAll(menuName);
        return ResultView.ok(hjMenuList);
    }

    /**
     * 新增菜单
     * @return
     */
    //@SaCheckPermission("menu:add")
    @PostMapping("/addMenu")
    public ResultView addMenu(@Validated SysMenuReq hjMenuReq) {
        return this.iHjMenuService.addMenu(hjMenuReq);
    }


    /**
     * 根据菜单ID获取当前数据
     * @return
     */
    //@SaCheckPermission("menu:get")
    @GetMapping("/getMenuId")
    public ResultView getMenuId(@NotNull(message = "菜单ID不能为空") String menuId) {
        return this.iHjMenuService.getMenuId(menuId);
    }

    /**
     * 修改菜单
     * @return
     */
    //@SaCheckPermission("menu:update")
    @PostMapping("/updateMenu")
    public ResultView updateMenu(@Validated SysMenuReq hjMenuReq) {
        return this.iHjMenuService.updateMenu(hjMenuReq);
    }


    /**
     * 删除菜单
     * @return
     */
    //@SaCheckPermission("menu:delete")
    @PostMapping("/deleteMenu")
    public ResultView deleteMenu(@NotNull(message = "菜单ID不能为空") String menuId) {
        return this.iHjMenuService.deleteMenu(menuId);
    }

}
